package com.lxy_s_springboot.lxy_s_springboot;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lxy_s_springboot.lxy_s_springboot.model.User;

public class JSONtest {
    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        User user = new User();
        user.setAge(19);
        user.setName("lxy");
        user.setGender(1);

        //对象转JSON
        String s = mapper.writeValueAsString(user);
        System.out.println(s);
        //json转对象
        User user2 = mapper.readValue(s, User.class);
        System.out.println(user2);
    }
}
